﻿<template>
    <div style="height:100%;">
        <Row>
            <Col span="24" class="col-margin">
            <!--根据需求删除不不要查询条件-->
           填报年份：
            <Select v-model="searchModel.FillInYear" placeholder="全部" :label-in-value="true" @on-change="initReport()" style="width:220px">
                <Option v-for="item in yearList" :value="item.DictValue" :key="item.DictValue">{{ item.DictText }}</Option>
            </Select>
            <!-- <Button icon="ios-search" type="ghost" @click="getPageData()">查询</Button> -->
            <Button icon="ios-download" type="info" @click="ExcelDown()" style="float:right;margin-right:20px" v-show="isCreated&&ReportStatus >1">数据导出</Button>
            <Upload :on-success="handleSuccess" :action="GetPostUrl()" style="float:right;margin-right:20px" v-show="isCreated&&ReportStatus <3">
                <Button type="success" icon="ios-cloud-upload-outline">数据导入</Button>
            </Upload>
            <Button icon="ios-download" type="warning" @click="TmpDown()" style="float:right;margin-right:20px">模板下载</Button>
            </Col>
        </Row>   
        <div v-show="isCreated">
        <Row class-name="col-margin">
            <Col span="12">
                <Button icon="plus" type="primary" :disabled="ReportStatus>2" @click="addItem()">新增</Button>            
            </Col>
            <Col span="12">
                <div style="float:right;font-size:16px;margin-right:50px;">当前状态：
                    <label style="font-size:16px;margin-right:5px;">
                        <span v-if="ReportStatus==0" class="Error">退回重报</span>
                        <span v-else-if="ReportStatus==1" class="NoReport">未填写</span>
                        <span v-else-if="ReportStatus==2" class="AlreadyReport">已填写</span>
                        <span v-else-if="ReportStatus==3" class="UpReport">已上报</span>
                        <span v-else-if="ReportStatus==4" class="Success">审核通过</span>
                    </label>
                    <span style="float:right;" v-show="ReportStatus==0">[<a @click="ReasonShow=true">未通过原因</a>]</span>
                </div>
            </Col>
        </Row>     
        <Row class-name="col-margin">
            <div id="griddiv" style="overflow-y:auto" v-bind:style="{ height: clientHeight + 'px' }">
                <Form ref="dataModel" :model="{dataList}">
                <table class="reptable">
                    <thead>
                        <tr>
                            <th rowspan="2">品种</th>
                            <th colspan="4">全年合计</th>
                            <th colspan="4">其中：大春作</th>
                            <th colspan="4">其中：秋作</th>
                            <th colspan="4">其中：冬作</th> 
                            <th rowspan="2" class="ivu-table-column-center">操作</th>                                                     
                        </tr>
                        <tr>
                            <th>面积(万亩）</th>
                            <th>总产（万吨）</th>
                            <th>平均亩产（公斤/亩）</th>                            
                            <th>总产值（万元）</th>
                            <th>面积(万亩）</th>
                            <th>总产（万吨）</th>
                            <th>平均亩产（公斤/亩）</th>                            
                            <th>总产值（万元）</th>
                            <th>面积(万亩）</th>
                            <th>总产（万吨）</th>
                            <th>平均亩产（公斤/亩）</th>                            
                            <th>总产值（万元）</th>
                            <th>面积(万亩）</th>
                            <th>总产（万吨）</th>
                            <th>平均亩产（公斤/亩）</th>                            
                            <th>总产值（万元）</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(dataModel,index) in dataList" :key="index">
                            <td>
                                <Form-item :prop="'dataList.' + index + '.Pvariety'" :rules="{required: true,message:'品种不能为空！', trigger: 'blur'}">
                                    <Select v-model="dataModel.Pvariety" placeholder="请选择" :label-in-value="true"  style="width:200px">
                                        <Option v-for="item in VarietyList" :value="item.DictText" :key="item.DictValue">{{ item.DictText }}</Option>
                                    </Select>
                                </Form-item>
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.YArea">                           
                                    <Form-item prop="YArea">
                                        <Input v-model="Model.dataModel.YArea" placeholder="请输入全年合计面积"></Input>
                                    </Form-item>
                                </Poptip> -->
                                <Form-item :prop="'dataList.' + index + '.YArea'" :rules="commonRule">
                                    <Input  v-model="dataModel.YArea" ></Input>
                                </Form-item>
                            </td>
                            <td> 
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.YYield">
                                    <Form-item  prop="YYield">
                                        <Input v-model="Model.dataModel.YYield" placeholder="请输入全年产量"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.YYield'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.YYield" ></Input>
                                </Form-item> 
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.YAvgMuYield">
                                    <Form-item prop="YAvgMuYield">
                                        <Input v-model="Model.dataModel.YAvgMuYield" placeholder="请输入全年平均亩产"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item prop="YAvgMuYield">
                                    <!-- <Input v-model="dataModel.YAvgMuYield" ></Input> -->
                                    <!-- {{dataModel.YAvgMuYield}} -->
                                    <!-- {{(dataModel.YArea&&dataModel.YYield&&dataModel.YArea!=0)?dataModel.YAvgMuYield=(dataModel.YYield/dataModel.YArea*1000).toFixed(2):dataModel.YAvgMuYield}} -->
                                    {{(dataModel.YYield/dataModel.YArea)?dataModel.YAvgMuYield=(dataModel.YYield/dataModel.YArea*1000).toFixed(2):0}}
                                </Form-item> 
                            </td> 
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.YOutput">
                                    <Form-item  prop="YOutput">
                                        <Input v-model="Model.dataModel.YOutput" placeholder="请输入全年总产值"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.YOutput'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.YOutput" ></Input>
                                </Form-item> 
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SArea">
                                    <Form-item  prop="SArea">
                                        <Input v-model="Model.dataModel.SArea" placeholder="请输入大春作面积"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.SArea'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.SArea" ></Input>
                                </Form-item> 
                            </td> 
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SYield">
                                    <Form-item  prop="SYield">
                                        <Input v-model="Model.dataModel.SYield" placeholder="请输入大春作产量"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.SYield'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.SYield" ></Input>
                                </Form-item>
                            </td> 
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SAvgMuYield">
                                    <Form-item  prop="SAvgMuYield">
                                        <Input v-model="Model.dataModel.SAvgMuYield" placeholder="请输入大春作平均亩产"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  prop="SAvgMuYield">
                                    <!-- <Input v-model="dataModel.SAvgMuYield" ></Input> -->
                                    {{(dataModel.SYield/dataModel.SArea)?dataModel.SAvgMuYield=(dataModel.SYield/dataModel.SArea*1000).toFixed(2):0}}
                                </Form-item> 
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SOutput">
                                    <Form-item  prop="SOutput">
                                        <Input v-model="Model.dataModel.SOutput" placeholder="请输入大春作总产值"></Input>
                                    </Form-item> 
                                </Poptip>  -->
                                <Form-item  :prop="'dataList.' + index + '.SOutput'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.SOutput" ></Input>
                                </Form-item>
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.AArea">
                                    <Form-item  prop="AArea">
                                        <Input v-model="Model.dataModel.AArea" placeholder="请输入秋作面积"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.AArea'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.AArea" ></Input>
                                </Form-item> 
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.AYield">
                                    <Form-item  prop="AYield">
                                        <Input v-model="Model.dataModel.AYield" placeholder="请输入秋作产量"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.AYield'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.AYield" ></Input>
                                </Form-item> 
                            </td> 
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.AAvgMuYield">
                                    <Form-item  prop="AAvgMuYield">
                                        <Input v-model="Model.dataModel.AAvgMuYield" placeholder="请输入秋作平均亩产"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  prop="AAvgMuYield">
                                    <!-- <Input v-model="dataModel.AAvgMuYield" ></Input> -->
                                    {{(dataModel.AYield/dataModel.AArea)?dataModel.AAvgMuYield=(dataModel.AYield/dataModel.AArea*1000).toFixed(2):0}}
                                </Form-item> 
                            </td> 
                            
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.AOutput">
                                    <Form-item  prop="AOutput">
                                        <Input v-model="Model.dataModel.AOutput" placeholder="请输入秋作总产值"></Input>
                                    </Form-item>
                                </Poptip>  -->
                                <Form-item  :prop="'dataList.' + index + '.AOutput'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.AOutput" ></Input>
                                </Form-item>
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.WArea">
                                    <Form-item  prop="WArea">
                                        <Input v-model="Model.dataModel.WArea" placeholder="请输入冬作面积"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.WArea'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.WArea" ></Input>
                                </Form-item> 
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.WYield">
                                    <Form-item  prop="WYield">
                                        <Input v-model="Model.dataModel.WYield" placeholder="请输入冬作产量"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.WYield'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.WYield" ></Input>
                                </Form-item>
                            </td>
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.WAvgMuYield">
                                    <Form-item  prop="WAvgMuYield">
                                        <Input v-model="Model.dataModel.WAvgMuYield" placeholder="请输入冬作平均亩产"></Input>
                                    </Form-item>
                                </Poptip> -->
                                <Form-item  prop="WAvgMuYield">
                                    <!-- <Input v-model="dataModel.WAvgMuYield" ></Input> -->
                                    {{(dataModel.WYield/dataModel.WArea)?dataModel.WAvgMuYield=(dataModel.WYield/dataModel.WArea*1000).toFixed(2):0}}
                                </Form-item>
                            </td>                              
                            <td>
                                <!-- <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.WOutput">
                                    <Form-item  prop="WOutput">
                                        <Input v-model="Model.dataModel.WOutput" placeholder="请输入冬作总产值"></Input>
                                    </Form-item> 
                                </Poptip> -->
                                <Form-item  :prop="'dataList.' + index + '.WOutput'" :rules="commonRule">
                                    <Input type="text" v-model="dataModel.WOutput" ></Input>
                                </Form-item> 
                           </td>
                           <td style="text-align: center;">                                
                                <i-button type="ghost" size="small" icon="ios-trash-outline" :disabled="ReportStatus >2" style="color:#FF0000" @click="delInfo(index)">
                                    <span style="color:#000;">删除</span>
                                </i-button>
                            </td> 
                        </tr>
                    </tbody>
                </table>
                </Form>
                <p style="margin-top:20px;font-size:14px">无可选品种请<a @click="showEdit=true" style="text-decoration:underline;">点击这里</a></p>
                <div class="divButton">
                    <Button type="primary" @click="save('dataModel')" :disabled="ReportStatus < 3  ? false:true ">保存</Button>
                    <Button type="primary" @click="DataUp()" :disabled="ReportStatus ==2  ? false:true ">上报</Button>
                </div>
                <Alert  type="error">
                    填报说明:
                    <p> 1.全省范围内从乡（镇）推广站起，逐级全面统计，由州（市）汇总后上报。</p> 
                    <p> 2.冬作包括冬作、早春作、小春作。</p>
                    <span slot="desc"></span>
                </Alert>
            </div>                      
            </Col>
        </Row> 
        </div>
        <div v-show="!isCreated" class="NoCreatedDiv">
            <h1>{{ReportLine}}</h1>
        </div>
        <Modal v-model="ReasonShow" :mask-closable="false" width="500"> 
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">未通过原因</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <div class="reasonDiv"><Input v-model="Opinion" type="textarea" readonly :autofocus="true" :rows="10"></Input></div>
            <p slot="footer"></p>
        </Modal>
        <Modal v-model="showEdit" :mask-closable="false" width="500"> 
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">添加品种</span>
            </p>
            <p slot="close">
                <!-- <Icon type="close-circled" color="red" size=25></Icon> -->
            </p>
            <Form ref="vForm">
                <Form-item  prop="VarietyName" >
                    <span style="color:red">*</span>品种名称：
                    <Input v-model="vModel.DictText" @on-blur="checkNameRepeat"></Input>
                    <p style="color:red" v-show="NameError">*此品种已存在，请仔细查看品种下拉列表！</p>
                    <p style="color:red" v-show="NameEmpty">*不能为空！</p>
                </Form-item> 
                <Form-item  prop="VarietyCode" >
                    <span style="color:red">*</span>品种代码：
                    <Input v-model="vModel.DictValue" @on-blur="checkCodeRepeat"></Input>
                    <p style="color:red" v-show="CodeError">*此代码已被使用，请更换！</p>
                    <p style="color:red" v-show="CodeEmpty">*不能为空！</p>
                </Form-item> 
            </Form>
            <div class="divButton">
                <Button type="primary" @click="saveVariety" >保存</Button>
                <Button type="ghost" @click="vCancel" >取消</Button>
            </div>
            <p slot="footer"></p> 
            <!-- {required: true, message: '不能为空！', trigger: 'blur'}, -->
        </Modal>              
    </div>
</template>
<script>
import axios from 'axios'
export default {
    data() {
        const validateData = (rule, value, callback) => {
            var temp = /^[0-9]\d*(\.\d+)?$/;
            if (value||value==0) {
                if (temp.test(value) == false) {
                    callback(new Error('必须是数字！'));
                }
                else {
                    callback();
                }
            } else {
                callback(new Error('不能为空！'));
            }
        };
        return {
            isCreated:false,//是否需要显示报表
            ReportLine:'',//不显示报表时所显示文字
            ReasonShow:false,
            showType: false,//编辑框弹出状态
            showEdit:false,//弹出品种编辑框
            CodeError:false,
            CodeEmpty:false,
            NameError:false,
            NameEmpty:false,
            yearList: this.GetGroupDict("ReportYear"),
            ReportStatus:'',
            ReportId:'',
            Opinion:'',
            dataList:[],
            VarietyList:this.GetlocaStorage("PotatoVariety"),
            AreaCode:this.GetlocaStorage("potUserinfo").AreaCode,
            commonRule:{validator: validateData, trigger: 'blur'},
            Model:{
                //本年度数据
                dataModel: {
                Id: '',
                ReportId:'', 
                Pvariety:'',
                YArea:'', 
                YAvgMuYield:'', 
                YYield:'', 
                YOutput:'', 
                SArea:'', 
                SAvgMuYield:'', 
                SYield:'', 
                SOutput:'', 
                AArea:'', 
                AAvgMuYield:'', 
                AYield:'', 
                AOutput:'', 
                WArea:'', 
                WAvgMuYield:'', 
                WYield:'', 
                WOutput:'', 
                },
                //上年数据
                oldDataModel: {
                Id: '',
                ReportId:'', 
                YArea:'', 
                YAvgMuYield:'', 
                YYield:'', 
                YOutput:'', 
                SArea:'', 
                SAvgMuYield:'', 
                SYield:'', 
                SOutput:'', 
                AArea:'', 
                AAvgMuYield:'', 
                AYield:'', 
                AOutput:'', 
                WArea:'', 
                WAvgMuYield:'', 
                WYield:'', 
                WOutput:'', 
                },
            },
            vModel:{//品种对象
                Id:'',
                DictText:'',//品种名称
                DictValue:'',//品种代码
                GroupCode:'PotatoVariety',//所属字典组代码
                GroupName:'马铃薯生产品种',//所属字典组名称
                Status:'1',//1启用，0停用
            },
            clientHeight: window.innerHeight - 226,//表格默认高度
            //查询模型：根据需求删除不不要查询条件
            searchModel: {
                ReportCode:'PotYearProduct',
                FillInYear:new Date().getFullYear()+'',
                PageNumber: 1, PageSize: 20
            },
        }           
    },
    mounted() {
        //table高度计算方法
        const that = this;
        window.onresize = () => {
            return (() => {
                that.clientHeight = window.innerHeight - 226;
            })()
        };
    },
    methods: {       
        getPageData() {
            var self = this;
            this.$http.get('PotYearProduct', {params:{AreaCode:this.AreaCode,FillInYear:this.searchModel.FillInYear}}).then(function (res) {
                if (res.data.status == 1) {
                    //self.Model.dataModel = res.data.model.DataModel;
                    //if(res.data.model.OldDataModel)
                    //self.Model.oldDataModel = res.data.model.OldDataModel;
                    self.dataList = res.data.model.list;
                    self.ReportStatus = res.data.model.ReportStatus;
                    self.ReportId = res.data.model.ReportId;
                    self.Opinion = res.data.model.Opinion;
                    self.isCreated = true;
                }
                else {
                    self.isCreated = false;
                    self.dataList = [];
                    self.ReportStatus = null;
                    self.ReportId = null;
                    self.Opinion = null;
                    self.ReportLine = '报表未生成！';
                    self.$Modal.error({ title: '提示信息', content: res.data.message });
                }
            });
        },
        //保存方法
        save(modelname) {
            var self = this;
            this.$refs[modelname].validate((valid) => {
                if (valid) {                    
                    this.$http.post('PotYearProduct', this.dataList).then(
                        function (res) {
                            if (res.data.status == 1) {
                                self.getPageData();//读取分页数据                                    
                                self.$Notice.success({ title: '保存成功！', desc: false });
                            }
                            else {
                                self.$Modal.warning({ title: "提示信息", content: res.data.message });
                            }
                    });
                }
                else{
                    self.$Modal.error({ title: "提示信息", content: '无法保存，请检查是否有未填项！' });
                }
            
            });
        },
        //新增
        addItem() {
            let model = {
                //编辑模型
                Id: '',
                ReportId:'', 
                Pvariety:'',
                YArea:'', 
                YAvgMuYield:'', 
                YYield:'', 
                YOutput:'', 
                SArea:'', 
                SAvgMuYield:'', 
                SYield:'', 
                SOutput:'', 
                AArea:'', 
                AAvgMuYield:'', 
                AYield:'', 
                AOutput:'', 
                WArea:'', 
                WAvgMuYield:'', 
                WYield:'', 
                WOutput:'', 
            };
            model.ReportId = this.ReportId;
            this.dataList.push(model);
        },
        //删除对象
        delInfo(index) {
            this.dataList.splice(index, 1);            
        },
        //数据上报
        DataUp() {
            var self = this;
            this.checkData();
        },
        convertNum: function (num) { //数字处理
            let s;
            if (isNaN(num)||num == null||num=='') {
                s= 0;
            }
            else{
                s= num*1;
            }
            return s;
        },
        PostUp(){
            var self = this;
            let model = new Object();
            model.Id = this.ReportId;
            model.Status = 3;
            model.Opinion = "";
            self.$Modal.confirm({
            title: "提示信息",
            content: "<p>数据上报后，不能再更改，是否继续上报？</p>",
            onOk: () => {
                this.$http.post("Report/PostUpStatus", model).then(function(res) {
                    if (res.data.status == 1) {
                        self.showType = false;
                        self.$Notice.success({ title: "数据上报成功！", desc: false });
                        self.getPageData();
                    } else {
                        self.$Modal.error({
                        title: "提示信息",
                        content: "数据上报失败!"
                        });
                    }
                });
            }});
        },
        checkData() {
            var self = this;
            let isOk = true;
            axios.all([
                self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '1'}}),
                self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '2'}}),
                self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '3'}}),
                ]).then(axios.spread(function (res1,res2,res3){
                        let smodel = self.listToModel(res1.data.model);
                        let amodel = self.listToModel(res2.data.model);
                        let wmodel = self.listToModel(res3.data.model);
                        if(self.dataList.length>0){
                        let ySArea = 0;//各品种大春面积合计
                        let yAArea = 0;//各品种秋作面积合计
                        let yWArea = 0;//各品种冬作面积合计
                        let ySYield = 0;//各品种大春产量合计
                        let yAYield = 0;//各品种秋作产量合计
                        let yWYield = 0;//各品种冬作产量合计
                        let ySOutput = 0;//各品种大春产值合计
                        let yAOutput = 0;//各品种秋作产值合计
                        let yWOutput = 0;//各品种冬作产值合计
                        for(var i=0 ; i<self.dataList.length;i++){
                            let imodel = self.dataList[i];
                            let t1 = imodel.YArea*1 - (imodel.SArea*1+imodel.AArea*1+imodel.WArea*1);
                            let t2 = imodel.YYield*1 - (imodel.SYield*1+imodel.AYield*1+imodel.WYield*1);
                            let t3 = imodel.YOutput*1 - (imodel.SOutput*1+imodel.AOutput*1+imodel.WOutput*1);
                            ySArea += imodel.SArea*1;
                            yAArea += imodel.AArea*1;
                            yWArea += imodel.WArea*1;
                            ySYield += imodel.SYield*1;
                            yAYield += imodel.AYield*1;
                            yWYield += imodel.WYield*1;
                            ySOutput += imodel.SOutput*1;
                            yAOutput += imodel.AOutput*1;
                            yWOutput += imodel.WOutput*1;
                            
                            if(t1.toFixed(0)!=0){
                                self.$Modal.error({ title: "提示信息", content: imodel.Pvariety+"全年合计面积不等于各季度面积之和! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(t2.toFixed(0)!=0){
                                self.$Modal.error({ title: "提示信息", content: imodel.Pvariety+"全年合计产量不等于各季度产量之和! 无法上报！" }); 
                            // return false;
                            isOk = false;
                            }
                            if(t3.toFixed(0)!=0){
                                self.$Modal.error({ title: "提示信息", content: imodel.Pvariety+"全年合计产值不等于各季度产值之和! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                        
                        }console.log(yWArea)
                        ySArea = ySArea.toFixed(4);
                        yAArea = yAArea.toFixed(4);
                        yWArea = yWArea.toFixed(4);
                        ySYield = ySYield.toFixed(4);
                        yAYield = yAYield.toFixed(4);
                        yWYield = yWYield.toFixed(4);
                        ySOutput = ySOutput.toFixed(4);
                        yAOutput = yAOutput.toFixed(4);
                        yWOutput = yWOutput.toFixed(4);
                        // var smodel = self.getSeasonData(self.AreaCode,self.searchModel.FillInYear,'1');
                        // var amodel = self.getSeasonData(self.AreaCode,self.searchModel.FillInYear,'2');
                        // var wmodel = self.getSeasonData(self.AreaCode,self.searchModel.FillInYear,'3');
                        if(smodel != null){
                            if(ySArea != smodel.Area){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的大春总面积不等于表二的大春总面积! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(ySYield != smodel.Yield){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的大春总产量不等于表二的大春总产量! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(ySOutput != smodel.Output){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的大春总产值不等于表二的大春总产值! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                        }
                        if(amodel != null){
                            if(yAArea != amodel.Area){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的秋作总面积不等于表二的秋作总面积! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(yAYield != amodel.Yield){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的秋作总产量不等于表二的秋作总产量! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(yAOutput != amodel.Output){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的秋作总产值不等于表二的秋作总产值! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                        }
                    if(wmodel != null){
                            if(yWArea != wmodel.Area){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的冬作总面积不等于表二的冬作总面积! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(yWYield != wmodel.Yield){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的冬作总产量不等于表二的冬作总产量! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                            if(yWOutput != wmodel.Output){
                                self.$Modal.error({ title: "提示信息", content: "填报冲突，表一的冬作总产值不等于表二的冬作总产值! 无法上报！" }); 
                                //return false;
                                isOk = false;
                            }
                        }
                    
                        }
                        else {
                            self.$Modal.error({ title: "提示信息", content: "没有数据! 无法上报！" }); 
                            isOk = false;
                        }
                        if(isOk){
                            self.PostUp();
                        }
                }))
        },
        listToModel(list){
            let model = new Object();
            model.Area = 0;
            model.Yield = 0;
            model.Output = 0;
            if (list.length > 0) {
                for (var i = 0; i < list.length; i++) {
                    var tItem = list[i];
                    model.Area += tItem.TotalArea;
                    model.Yield += tItem.TotalYield;
                    model.Output += tItem.TotalOutput;
                }
                model.Area = model.Area.toFixed(4);
                model.Yield = model.Yield.toFixed(4);
                model.Output = model.Output.toFixed(4);
            }
            return model;
        },
        getSeasonData(AreaCode, FillInYear, TimesCycle){
            var self = this;
            let model = new Object();
            model.Area = 0;
            model.Yield = 0;
            model.Output = 0;
            this.$http.get("PotSeasonProduct", { params: { AreaCode: AreaCode,FillInYear:FillInYear,TimesCycle:TimesCycle } }).then(
                function (res) {
                    if (res.data.status == 1) {
                        self.seasondataList = res.data.model;                         
                        if(self.seasondataList.length>0){
                            for(var i=0; i<self.seasondataList.length; i++){
                                var tItem = self.seasondataList[i];
                                model.Area += tItem.TotalArea;
                                model.Yield += tItem.TotalYield;
                                model.Output += tItem.TotalOutput;                                
                            }
                            model.Area = model.Area.toFixed(4);
                            model.Yield = model.Yield.toFixed(4);
                            model.Output = model.Output.toFixed(4);  
                            return model;                          
                        }
                        else{
                            return null;
                        }                                              
                    }
                }
            );
            
        },
        //模板下载
        TmpDown:function(){
            window.open(this.$http.defaults.baseURL + "Report/GetTemplateData?ReportCode=" + this.searchModel.ReportCode);
        },
         //导入
        GetPostUrl() {
            var url = this.$http.defaults.baseURL + "PotYearProduct/PostImportData?ReportId=" + this.ReportId;
            return url;
        },
        //导入成功反馈事件
        handleSuccess(res, file) {
            var self = this;
            self.getPageData();
            if(res.status == -1){
                self.$Modal.warning({
                    title: "提示信息",
                    content: res.message
                });
            }else{
                //self.save("dataModel");
                self.$Notice.success({
                    title: '数据导入成功！',
                    desc: false
                });
            }            
        },
        //导出
        ExcelDown: function () {           
           window.open(this.$http.defaults.baseURL + "PotYearProduct/GetExcelData?FillInYear="  + this.searchModel.FillInYear + "&&AreaCode=" + this.AreaCode);
        },
        checkNameRepeat(){
            var self = this;
            this.NameError = false;
            this.NameEmpty = false;
            if(self.VarietyList.length >0){
                for(var i=0; i<self.VarietyList.length;i++){
                    var Item = self.VarietyList[i];
                    if(!this.vModel.DictText){
                        this.NameEmpty = true;
                    }
                    else if(this.vModel.DictText == Item.DictText){
                        this.NameError = true;
                    }
                }
            }
            
        },
        checkCodeRepeat(){
            var self = this;
            this.CodeError = false;
            this.CodeEmpty = false;
            if(self.VarietyList.length >0){
                for(var i=0; i<self.VarietyList.length;i++){
                    var Item = self.VarietyList[i];
                    if(!this.vModel.DictValue){
                        this.CodeEmpty = true;
                    }
                    else if(this.vModel.DictValue == Item.DictValue){
                        this.CodeError = true;
                    }
                }
            }
        },
        vCancel(){
            this.showEdit = false;
            this.vModel.DictText = '';
            this.vModel.DictValue = '';
        },
        getVariety(){
            var self = this;
            this.$http.get('Dict/GetDicByGroupCode',{params:{GroupCode:'PotatoVariety'}}).then(function(res){
                self.VarietyList = res.data.model;
                self.SetlocaStorage("PotatoVariety",self.VarietyList);
            })
        },
        saveVariety(){
            var self = this;
            this.$refs['vForm'].validate((valid) => {
                if (valid) {
                    this.$http.post('Dict', self.vModel).then(function (res) {
                        if (res.data.status == 1) {
                            self.showEdit = false;
                            self.getVariety();
                            self.$Notice.success({ title: '保存成功！', desc: false });
                        }
                        else {
                            self.$Modal.warning({ title: "提示信息", content: "品种添加失败,请与管理员联系!" });
                        }
                    });
                } else {
                    self.$Modal.warning({
                        title: "提示信息",
                        content: "不满足条件，无法保存！"
                    });
                }
            })
        },
        initReport(){
            var today = new Date();
            let currentYear = today.getFullYear();
            let currentMonth = today.getMonth() + 1;
            if(this.searchModel.FillInYear*1 == currentYear &&currentMonth==12){
               this.getPageData();
            }
            else if(this.searchModel.FillInYear*1 == currentYear-1 && currentMonth >= 1 && currentMonth <= 5){
                this.getPageData();
            }
            else if(this.searchModel.FillInYear < currentYear){
                this.getPageData();
            }
            else {
                this.isCreated = false;
                this.ReportLine = '不在填报时间内！';
            }
        }
        
    },
    computed:{
        computYAvgMuYield(index){
            let dataItem = this.dataList[index];
            if(dataItem.YArea&&dataItem.YYield&&dataItem.YArea!=0){
                dataItem.YAvgMuYield=(dataItem.YYield/dataItem.YArea).toFixed(2)
            }
            else{
                dataItem = 0.00;
            }
        },
    },
    //创建Vue页面方法
    created: function () {
        //创业Vue前调用获取this.datas: {},//table数据对象
        this.initReport();
    },
    watch: {
        //需要监听的在此处新增监听对象
    }
}
</script>
